package com.mika.web.advice;

import com.mika.web.Result;
import com.mika.web.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @Author XiaoJiangShi
 * @Date 2022/8/22 10:43
 * @Blog blog.XiaoJiangShi.net/996.mba
 * @Description: 全局异常处理
 */
@Slf4j
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result<String> exception(BusinessException e){
        log.warn("异常信息为：[{}]",e.getMessage());
        return Result.fail(e.getMessage());
    }
}

